package com.heima.wemedia.controller.v1;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.pojos.WmUser;
import com.heima.wemedia.service.WmUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("/api/v1/user")
public class WmUserController {

    @Autowired
    WmUserService wmUserService;

     @GetMapping("findByName/{name}")
    public ResponseResult findByName(@PathVariable String name){
         WmUser wmUser = wmUserService.getOne(Wrappers.<WmUser>lambdaQuery().eq(WmUser::getName, name));
         return ResponseResult.okResult(wmUser);
     }

    @PostMapping("save")
    public ResponseResult save(@RequestBody WmUser user){
         user.setCreatedTime(new Date());
         //user.id ==null
         wmUserService.save(user); //先创建自媒体账户 创建作者信息 需要自媒体账户
         //user.id == 有值
         return ResponseResult.okResult(user);
    }
    

}
